package com.example.agricultural_big_data.service.serviceimpl;
import com.alibaba.fastjson.JSONObject;
import com.example.agricultural_big_data.mapper.MapMapper;
import com.example.agricultural_big_data.pojo.*;
import com.example.agricultural_big_data.service.MapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiao yang
 * @Description: 种植园地图
 * @date 2021/2/1415:00
 */
@Service
public class MapServiceImpl implements MapService {
    @Autowired
    Result result;
    @Autowired
    MapMapper mapMapper;
    @Override
    public JSONObject getPlantations() {
        JSONObject jsonObject;
        List<Plantation> plantations=mapMapper.getPlantations();
        ArrayList<Object> list=new ArrayList();
        for (Plantation p:plantations) {
            ArrayList plantation=new ArrayList();
//            plantation.add(0,p.getLongitude());
//            plantation.add(1,p.getLatitude());
//            plantation.add(2,p.getId());
//            plantation.add(3,p.getName());
//            plantation.add(4,p.getAltitude());
//            plantation.add(5,p.getManual());
//            plantation.add(6,p.getPhoto()); //种植园地址
//            plantation.add(7,p.getMarket().getContact());
//            plantation.add(8,p.getMarket().getScale());
//            plantation.add(9,p.getMarket().getPhoto());//销售点照片地址
            JSONObject jsonObject1=new JSONObject();
            jsonObject1.put("position",plantation);
            list.add(jsonObject1);
        }
        jsonObject=result.responseResult(ResultCode.success.getStatusCode(),ResultCode.success.getMsg(),list);
        return jsonObject;
    }

    @Override
    public JSONObject getPlant_avgsByid(String id) {
        JSONObject jsonObject;
        List<PlantAvg> plant_avgs=mapMapper.getPlant_avgsByid(id);
        if (plant_avgs!=null){
            jsonObject=result.responseResult(ResultCode.success.getStatusCode(),ResultCode.success.getMsg(),plant_avgs);
        }else {
            jsonObject=result.responseResult(ResultCode.find_error.getStatusCode(),ResultCode.find_error.getMsg());
        }
        return jsonObject;
    }
}
